<?php
//OPTIMIZEME : ce code doit être optimisié
class RolesManagerByAction 
{
	protected $_data;
	
	public function RolesManagerByAction($actionid,$urlUpdate)
    {
    	if(!$actionid) return ;
    	
    	$aclRights = new Wmp_Model_AclrightsTable();  
    	$aclRights = $aclRights->getRolesByAction($actionid,true);
    	
    	$checkedList = array();
    	$descriptionPrivilege = array();
    	foreach($aclRights as $right) {
    		$checkedList[$right->role][$right->privilege] = "checked checked";
    	}
    	
        	
        $translate =  zend_registry::get('Zend_Translate');		
    	$_data ="<form method='post' action='".$urlUpdate."' >"; //URGENT à corriger par php self
    	$_data .="<input type='hidden' name='modname' />";
        
    	$_data .="<table width='100%' border='1'>";
    	$_data .='<tr>
    				<th>'.$translate->_('role').'</th>
    				<th>'.$translate->_('allow-privilege').'</th>
    				<th>'.$translate->_('deny-privilege').'</th>
    				<th>'.$translate->_('inherits-privilege').'</th>
    			</tr>';    	      
        
        $roles = new Wmp_Model_AclRolesTable();
        $roles = $roles->fetchAll();        
       
        foreach($roles as $role) {
        	$inheritsChecked = ($checkedList[$role->name]['allow'] || $checkedList[$role->name]['deny']) ? '': 'checked checked';
        	
        	$_data .='<tr>';
        	$_data .='<td>'. $role->name.'</td>';
        	$_data .='<td><input type="radio" name="privilege['.$role->name.']" value="allow" '.@$checkedList[$role->name]['allow'].' /></td>';
        	$_data .='<td><input type="radio" name="privilege['.$role->name.']" value="deny" '.@$checkedList[$role->name]['deny'].' /></td>';
        	$_data .='<td><input type="radio" name="privilege['.$role->name.']" value="parent" '.$inheritsChecked.' /></td>';
        	$_data .='</tr>';
        	
        	$inheritsChecked="";
        }

        $_data .='</table>';
        $_data .='<input type="submit" value="'.$translate->_('validate').'" name="submitRoleAction">';
        $_data .='</form>';

        $this->_data = $_data;
    }
    
    public function getData()
    {
    	return $this->_data;
    }
}